package com.bawei.liuzhanlin20210806.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bawei.liuzhanlin20210806.R;
import com.bawei.liuzhanlin20210806.model.bean.NrBean;
import com.bawei.liuzhanlin20210806.view.activity.Main3Activity;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Time: 2021/8/6
 * Author:liuzhanlin
 * Description:zhuangao6
 */
public class NrAdapter extends RecyclerView.Adapter<NrAdapter.MyHandler> {

    private List<NrBean.DataDTO.ResultDTO.TrainsDTO> list;
    private Context context;

    public NrAdapter(List<NrBean.DataDTO.ResultDTO.TrainsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public MyHandler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHandler(LayoutInflater.from(context).inflate(R.layout.b, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHandler holder, int position) {
        holder.tvMc.setText(list.get(position).title);
        holder.sdv.setImageURI("http://172.17.27.50/moni/"+list.get(position).image);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Main3Activity.class);
                intent.putExtra("sp","http://172.17.27.50/moni/"+list.get(position).playurl);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHandler extends RecyclerView.ViewHolder {
        @BindView(R.id.sdv)
        SimpleDraweeView sdv;
        @BindView(R.id.tv_mc)
        TextView tvMc;
        public MyHandler(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
